#include <vector>
using namespace std;

class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int size = nums.size();
        vector<int> dp(size);
        dp[0] = nums[0];
        int maxsum = nums[0];
        for (int i = 1; i<size; ++i)
        {
            dp[i] = max(nums[i], dp[i-1]+nums[i]);
            maxsum = max(maxsum, dp[i]);
        }
        return maxsum;
    }
};